package cn.itcast.service.impl;

import cn.itcast.domain.User;
import cn.itcast.mapper.UserMapper;
import cn.itcast.service.UserService;
import cn.itcast.utils.MapperUtils;
import cn.itcast.utils.UuidUtils;
import com.github.pagehelper.PageHelper;

import java.util.List;

public class UserServiceImpl implements UserService {
    private UserMapper mapper = null;

    /**
     * 调用工具类方法 MapperUtils.getMapper获取mapper
     *
     * @return
     */
    public List<User> findAll(Integer pageNum) {
        mapper = (UserMapper) MapperUtils.getMapper(UserMapper.class);
        //分页查询
        PageHelper.startPage(pageNum,5);
        List<User> userList = mapper.findAll();
        return userList;
    }

    //添加功能
    public void add(User user) {
        String uuid = UuidUtils.getUuid();
        user.setId(uuid);
        mapper.add(user);
    }

    //根据id删除一条用户
    public void deleteByIds(String uids) {
        if (uids.length() > 0 && uids != null) {
            String[] uid = uids.split(",");

            mapper.deleteByIds(uid);

        }

    }

    //查询一条用户信息
    public User findById(String uid) {

        return mapper.findById(uid);
    }

    //根据id修改用户
    public void update(User user) {
        mapper.update(user);
    }

}
